#include "ParticleObj.h"

ParticleObj::ParticleObj(
	double dt,
	int radius,
	Double2 x,
	Double2 v,
	Double2 a,
	Double2 a_delta_range,
	int lifespan
) {
	_dt = dt;
	_radius = radius;
	_x = x;
	_v = v;
	_a = a;
	_distribution = std::uniform_real_distribution<double>(a_delta_range.x, a_delta_range.y + 1);
	_a_delta_range = a_delta_range;
	_lifespan = lifespan;
}

void ParticleObj::update(std::mt19937& random_engine) {
	if (!_is_active)return;
	_x.x += _v.x * _dt;
	_x.y += _v.y * _dt;
	_v.x += _a.x * _dt;
	_v.y += _a.y * _dt;
	_a.x += _distribution(random_engine);
	_a.y += _distribution(random_engine);
	_lifespan--;
	if (_lifespan <= 0)_shrink();
}

void ParticleObj::_shrink() {
	_radius--;
	if (_radius < 0)_is_active = false;
}
